package com.hp.bon.sgw.wkflow.impl;

import java.util.concurrent.atomic.AtomicInteger;

import com.hp.bon.sgw.util.Comutils;
import com.hp.bon.sgw.wkflow.FlowVarObj;

public class ComReqSerialGen extends FlowVarObj {

	@Override
	public Object getProperty(String express) {
		return getReqSerial();
	}

	private static AtomicInteger reqSerialNum = new AtomicInteger(0);

	private static String getReqSerial() {
		return Comutils.formatTime(System.currentTimeMillis(), "yyyyMMddHHmmss") + genReqSerialNum() + "05";
	}

	/**
	 * 生成ReqSerial流水号
	 * 
	 * @return
	 */
	private static String genReqSerialNum() {
		if (reqSerialNum.get() == 99999999) {
			reqSerialNum.set(0);
		}
		int newValue = reqSerialNum.incrementAndGet();

		StringBuilder result = new StringBuilder(Integer.toString(newValue));
		int len = result.length();
		for (int i = len; i <= 8; i++) {
			result.insert(0, "0");
		}
		return result.toString();
	}

}
